#include "StdAfx.h"
#include "ImageHeader.h"
#include "Endiannes.h"

namespace MnistDigit
{
	std::istream& operator>> (std::istream& i, ImageHeader& imageHeader)
	{
		i.read( (char*)( &imageHeader), sizeof(imageHeader)) ;

		Endiannes::MSB2OS(imageHeader.m_magic_number);
		Endiannes::MSB2OS(imageHeader.m_number_of_images);
		Endiannes::MSB2OS(imageHeader.number_of_rows);
		Endiannes::MSB2OS(imageHeader.number_of_columns);
		if(imageHeader.m_magic_number!=2051 
			|| (imageHeader.m_number_of_images!=10000 && imageHeader.m_number_of_images!=60000)
			|| imageHeader.number_of_rows!=28
			|| imageHeader.number_of_columns!=28
			)
			throw std::logic_error( "operator>> (std::istream& i, ImageHeader");

		return i;
	}

}